package com.block.channel.factory;

import com.block.channel.enums.MonitorChannelEnum;
import com.block.channel.service.IChannelCallbackService;
import com.block.channel.service.IChannelMonitorService;
import com.block.channel.service.monitor.*;
import com.block.common.util.ApplicationContextUtil;

import java.util.HashMap;
import java.util.Map;

public class MonitorChannelFactory {

    private static final Map<String, Class<? extends IChannelMonitorService>> serviceMap = new HashMap<>();

    private static final Map<String, Class<? extends IChannelCallbackService>> callServiceMap = new HashMap<>();

    static {
        serviceMap.put(MonitorChannelEnum.HUAWEI.getValue(), HuaWeiMonitorService.class);
        serviceMap.put(MonitorChannelEnum.VIVO.getValue(), VivoMonitorService.class);

        serviceMap.put(MonitorChannelEnum.JUGAO.getValue(), JuGaoMonitorService.class);
        serviceMap.put(MonitorChannelEnum.BAIDU.getValue(), BaiDuMonitorService.class);
        serviceMap.put(MonitorChannelEnum.RONGYAO.getValue(), RongYaoMonitorService.class);

        /***********结果回调通知*************/

        callServiceMap.put(MonitorChannelEnum.VIVO.getValue(), VivoMonitorService.class);
        callServiceMap.put(MonitorChannelEnum.BAIDU.getValue(), BaiDuMonitorService.class);

    }

    public static IChannelMonitorService getService(String channelCode){
        if (serviceMap.containsKey(channelCode)){
            Class<? extends IChannelMonitorService> aClass = serviceMap.get(channelCode);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }

    public static IChannelCallbackService getCallbackService(String channelCode){
        if (callServiceMap.containsKey(channelCode)){
            Class<? extends IChannelCallbackService> aClass = callServiceMap.get(channelCode);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }

}
